Add robolectric basic sample#146
Conversation
| This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio is recommended. | ||
|
|
||
| 1. Download the project code, preferably using `git clone`. | ||
| 1. Open the Android SDK Manager (*Tools* Menu | *Android*) and make sure you have installed the *Android Support Repository* under *Extras*. (For more Information click [here](http://developer.android.com/tools/testing-support-library/index.html#setup)) |
There was a problem hiding this comment.
This step is not necessary for Robolectric... it might not be necessary for instrumentation tests now since we're in gMaven @slinzner ?
| compileSdkVersion 26 | ||
| buildToolsVersion rootProject.buildToolsVersion | ||
| defaultConfig { | ||
| applicationId "com.example.android.testing.robolectric.BasicSample" |
There was a problem hiding this comment.
I don't think application id's usually have capital letters in do they? Is this the pattern in the other samples?
There was a problem hiding this comment.
Yes, it matches the other examples (it matches the package name which is uppercase).
| @Test | ||
| public void createActivityFromIntent() { | ||
| Intent intent = new Intent(RuntimeEnvironment.application, MainActivity.class); | ||
| Robolectric.buildActivity(MainActivity.class, intent).setup().get(); |
There was a problem hiding this comment.
This isn't really asserting anything, for this to be valuable you really want to make some assertions, like, have the activity render some data in the test fields that you specified in the intent for example.
|
|
||
| @Test | ||
| public void pauseResumeActivity() { | ||
| ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class); |
There was a problem hiding this comment.
I don't really like this kind of test as it is not demonstrating any behaviour.
| public void setUp() { | ||
| Intent intent = new Intent(RuntimeEnvironment.application, ShowTextActivity.class); | ||
| intent.putExtra(ShowTextActivity.KEY_EXTRA_MESSAGE, MESSAGE); | ||
| activity = Robolectric.buildActivity(ShowTextActivity.class, intent).setup().get(); |
There was a problem hiding this comment.
Robolectric.setupActivity()
There was a problem hiding this comment.
I don't think it works with an intent does it?
| @@ -0,0 +1,69 @@ | |||
| /* | |||
| * Copyright 2015, The Android Open Source Project | |||
| @@ -0,0 +1,30 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <!-- | |||
| ~ Copyright (C) 2015 The Android Open Source Project | |||
| --> | ||
| <resources> | ||
| <style name="AppTheme" parent="android:Theme.Holo.Light"/> | ||
| </resources> No newline at end of file |
| @@ -0,0 +1,37 @@ | |||
| package com.example.android.testing.robolectric.BasicSample; | |||
| ext { | ||
| buildToolsVersion = "25.0.0" | ||
| supportLibVersion = "25.4.0" | ||
| runnerVersion = "1.0.0" |
| @@ -1,5 +1,6 @@ | |||
| integration/ServiceTestRuleSample | |||
| runner/AndroidJunitRunnerSample | |||
| ui/robolectric/BasicSample | |||
There was a problem hiding this comment.
this should be under unit/ not ui/
There was a problem hiding this comment.
Moved to unit/BasicRobolectricSample.
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| testOptions { |
There was a problem hiding this comment.
Please add a comment to indicate that this is required in order for Robolectric to work
| } | ||
|
|
||
| ext { | ||
| buildToolsVersion = "25.0.0" |
There was a problem hiding this comment.
Update this to the latest version, which I guess should be 26.0.0
slinzner
left a comment
There was a problem hiding this comment.
LGTM, thanks for the changes. Please run the ./test_all.sh script before submitting to make sure everything still works.
|
Checked ./test_all.sh : ALL TESTS PASS |
|
Curious if all of the tests passed on Oct 6, 2017, why was this never merged in? |
Add example tests using robolectric. Copied the espresso BasicSample as is, with some string substitutions.